{__NOLAYOUT__}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link rel="stylesheet" type="text/css" href="/agent/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="/agent/css/add_agent.css"/>
    <script type="text/javascript" src="/agent/js/jquery.1.9.1.js" ></script>
    <script type="text/javascript" src="/agent/js/layer.js"></script>
    <link rel="stylesheet" type="text/css" href="/agent/css/layer.css" />
    <script type="text/javascript" src="/agent/js/mobileSelect.js"></script>
    <link rel="stylesheet" type="text/css" href="/agent/css/mobileSelect.css"/>
    <script type="text/javascript" src="/agent/js/iScroll.js" ></script>
    <script type="text/javascript" src="/agent/js/Mdate.js" ></script>
    <link rel="stylesheet" href="/agent/css/Mdate.css" />
    <script type="text/javascript" src="/agent/js/rem.js" ></script>
    <title>修改代理商</title>
</head>
<body style="background-color: #fff;">
<form name="form1" id="form1" action="" method="post">
    <h2 style="font-size: 0.33rem;color: #f3494c;padding: 0.4rem 0.3rem 0 0.3rem;">基本信息</h2>
    <!--基本信息-->
    <ul>
        <li>
            <span style="width: 1.6rem;display: inline-block;">代理商名称</span>
            <input style="width: 74%;height: 0.7rem;" type="text" name="row[agent_name]" id="name" disabled value="{$agent.agent_name}" placeholder="填写代理商名称" />
        </li>
        <li>
            <span style="width: 1.6rem;display: inline-block;">所在地区</span>
            <div id="trigger4" class="trigger4" style="text-indent:0.5em;display: inline-block;border: 1px solid #e2e2e2;width: 74%;height: 0.7rem;line-height: 0.7rem;border-radius: 5px;">
                {$agent_area.mergename}
            </div>
            <input type="hidden" name="row[province]" id="province" value="{$agent.province}" />
            <input type="hidden" name="row[city]" id="city"  value="{$agent.city}" />
            <input type="hidden" name="row[area]" id="area"  value="{$agent.area}" />
        </li>
        <li>
            <span style="width: 1.6rem;display: inline-block;">详细地址</span>
            <input style="width: 74%;height: 0.7rem;" type="text" name="row[address]" id="address" value="{$agent.address}" placeholder="填写详细地址" />
        </li>
        <li>
            <span style="width: 1.6rem;display: inline-block;">联系人</span>
            <input style="width: 74%;height: 0.7rem;" type="text" name="row[agent_contact]" id="contact" value="{$agent.agent_contact}" placeholder="填写联系人" />
        </li>
        <li>
            <span style="width: 1.6rem;display: inline-block;">手机号码</span>
            <input style="width: 74%;height: 0.7rem;" type="number" name="row[agent_phone]" id="tel" value="{$agent.agent_phone}" placeholder="填写手机号码" />
        </li>
        <li>
            <span style="width: 1.6rem;display: inline-block;">传真</span>
            <input style="width: 74%;height: 0.7rem;" type="number" name="row[agent_fax]" id="fax" value="{$agent.agent_fax}" placeholder="填写传真" />
        </li>
        <li>
            <span style="width: 1.6rem;display: inline-block;">邮编</span>
            <input style="width: 74%;height: 0.7rem;" type="text" name="row[agent_code]" id="youbian" value="{$agent.agent_code}" placeholder="填写邮编" />
        </li>
    </ul>
    <div style="width: 100%;height: 0.18rem;background: #F5F5F5;"></div>
    <h2 style="font-size: 0.33rem;color: #f3494c;padding: 0.4rem 0.3rem 0 0.3rem;">代理信息</h2>
    <!--代理信息-->
    <ul class="daili">
        <li>
            <span style="width: 1.6rem;display: inline-block;">代理地区</span>
            <input style="width: 74%;height: 0.7rem;" type="text" name="row[agent_region]" id="agent_area" value="{$agent.agent_region}" placeholder="填写代理地区" />

        </li>
        <li>
            <span style="width: 1.6rem;display: inline-block;">代理期限</span>
            <p class="agent_date" id="dateShowBtn">代理开始日期
                <input type="text" disabled="disabled" id="dateSelectorOne" data-year="{:date('Y',$agent.term_start)}" data-month="{:date('m',$agent.term_start)}" data-day="{:date('d',$agent.term_start)}" value="{:date('Y-m-d',$agent.term_start)}" placeholder="选择日期">
                <input type="hidden" name="row[term_start]" id="term_start" data-year="{:date('Y',$agent.term_start)}" data-month="{:date('m',$agent.term_start)}" data-day="{:date('d',$agent.term_start)}"  value="{:date('Y-m-d',$agent.term_start)}">
            </p>
            <p class="agent_date" id="dateStopBtn">代理结束日期
                <input type="text" disabled="disabled" id="dateSelectorTwo" data-year="{:date('Y',$agent.term_end)}" data-month="{:date('m',$agent.term_end)}" data-day="{:date('d',$agent.term_end)}"  value="{:date('Y-m-d',$agent.term_end)}" placeholder="选择日期">
                <input type="hidden" name="row[term_end]" id="term_end"  data-year="{:date('Y',$agent.term_end)}" data-month="{:date('m',$agent.term_end)}" data-day="{:date('d',$agent.term_end)}"  value="{:date('Y-m-d',$agent.term_end)}" >
            </p>
        </li>
        <li style="padding: 0.3rem 0;">
            <span style="width: 2.2rem;display: inline-block;">代理产品及折扣</span>
            <span class="add_zhekou">+</span>
            <div class="addzhekoudata" style="display: block;">
                {volist name="$cate_info" id="cate" key="k"}
                    {if $cate.discount}
                        <p class="zhekou" style="display: block;">
                            <span class="product">{$cate.name}</span>
                            <span style="float: right;margin-right: 0.1rem;">{$cate.discount}折</span>
                            <span class="zhe"></span>
                        </p>
                    {/if}
                {/volist}
            </div>
        </li>
        <div class="zhekou_mask">
            <div class="myzhekou">
                <h2>请选择代理产品及折扣</h2>
                <ul>
                    <img class="zhekou_close" src="/agent/img/cha.png"/>
                    {volist name="$cate_info" id="cate" key="k"}
                        <li>
                            <span class="custom-checkbox">
                                <input type="checkbox" {$cate.discount ? 'checked':''}  name="row[product_discount][{$k}][id]" data-key="{$k}" data-name="{$cate.name}" value="{$cate.id}" />
                                <label>{$cate.name}</label>
                            </span>
                            <span>
                                <input type="number" name="row[product_discount][{$k}][discount]" class="product_discount_{$k}" value="{$cate.discount ? $cate.discount:''}" />
                                <label>折</label>
                            </span>
                        </li>
                    {/volist}
                    <div class="submit">提交</div>
                </ul>
            </div>
        </div>
        <li>
            <span style="width: 1.6rem;display: inline-block;float: left;margin-top: 0.2rem;">业务员</span>
            <div  style="text-indent:0.5em;overflow:hidden;display: inline-block;border: 1px solid #e2e2e2;width: 74%;height: 0.7rem;line-height: 0.7rem;border-radius: 5px;">
                <input  name="" style="border: none;width: 100%;" type="text" id="clerk" value="" placeholder="{$agent.clerk_text}">
            </div>
            <input type="hidden" name="row[clerk]" id="yewuyuan" value="{$agent.clerk}" />
            <input type="hidden" name="row[docking]"  value="{$auth->userid}" />
            <ul class="sou_result">
            </ul>
        </li>
    </ul>
    <div style="width: 100%;height: 0.18rem;background: #F5F5F5;"></div>
    <h2 style="font-size: 0.33rem;color: #f3494c;padding: 0.4rem 0.3rem 0 0.3rem;">财务信息</h2>
    <!--财务信息-->
    <ul>
        <li>
            <span style="width: 1.6rem;display: inline-block;">发票抬头</span>
            <input style="width: 74%;height: 0.7rem;" type="text" name="row[finance_invoice]" id="fapiao" value="{$agent.finance_invoice}" placeholder="填写发票抬头" />
        </li>
        <li>
            <span style="width: 1.6rem;display: inline-block;">纳税人号</span>
            <input style="width: 74%;height: 0.7rem;" type="text" name="row[finance_taxnumber]" id="nashui" value="{$agent.finance_taxnumber}" placeholder="填写纳税人号" />
        </li>
        <li>
            <span style="width: 1.6rem;display: inline-block;">开户名称</span>
            <input style="width: 74%;height: 0.7rem;" type="text" name="row[account_name]" id="bank_name" value="{$agent.account_name}" placeholder="填写开户名称" />
        </li>
        <li>
            <span style="width: 1.6rem;display: inline-block;">开户银行</span>
            <input style="width: 74%;height: 0.7rem;" type="text" name="row[account_bank]" id="bank" value="{$agent.account_bank}" placeholder="填写开户银行" />
        </li>
        <li>
            <span style="width: 1.6rem;display: inline-block;">银行账号</span>
            <input style="width: 74%;height: 0.7rem;" type="number" name="row[bank_number]" id="bank_sn" value="{$agent.bank_number}" placeholder="填写银行账号" />
        </li>
    </ul>
    <input class="button" id="sub" type="submit" value="保存"/>
</form>
</body>
<script>
  var style = document.createElement("style");
  var text = document.createTextNode(".sou_result li:hover{background: #e8e8e8;}");
  style.appendChild(text);
  document.body.appendChild(style);

  $(document).on("click", '#dateSure', function(){
    var year = $('#dateSelectorOne').attr('data-year');
    var month = $('#dateSelectorOne').attr('data-month');
    var day = $('#dateSelectorOne').attr('data-day');
    var yeartwo = $('#dateSelectorTwo').attr('data-year');
    var monthtwo = $('#dateSelectorTwo').attr('data-month');
    var daytwo = $('#dateSelectorTwo').attr('data-day');
    $('#term_start').val(year+'-'+month+'-'+day);
    $('#term_end').val(yeartwo+'-'+monthtwo+'-'+daytwo);
  });

  $('#clerk').bind('input propertychange', function(){
    if($(this).val()){
      $.ajax({
        type: "post",
        url: "/api/base/user",
        data:{showField:"username",keyField:'userid',pageSize:10,'q_word':[$(this).val()]},
        dataType: "json",
        success: function(res){
          if(res.list.length == 0)
          {
            $('.sou_result li').remove();
            $('.sou_result').hide();
            return false;
          }
            $('.sou_result').show();
            var html = '';
            $.each(res.list,function (index,value){
                html +='<li onclick="checked($(this));" data-userid="'+value.userid+'">'+value.username+'</li>'
            });
          $('.sou_result li').remove();
          $('.sou_result').append(html);
            //命名显示在input框   value = userid
        }
      });
    }else{
      $('.sou_result li').remove();
      $('.sou_result').hide();
    }
  });
  function checked(val)
  {
    $('#clerk').val(val.text());
    $('#yewuyuan').val(val.attr('data-userid'));
    $('.sou_result').hide();
  }

  $(document).ready(function(){
    var myHeight = $(window).height();
    $(".zhekou_mask").css('height',myHeight);
    $('.add_zhekou').click(function(){
      $('.zhekou_mask').show();
    });
    $('.zhekou_close').click(function(){
      $('.zhekou_mask').hide();
    });
    $('.submit').click(function(){
      var product_discount =[];
      $('.zhekou').remove();
      $(":checked").each(function(index){
        var discount = $('.product_discount_'+$(this).attr('data-key')).val();
        product_discount.push({id:$(this).val(),discount:discount,name:$(this).attr('data-name')});
        var html = "<p class=\"zhekou\">\n" +
          "                <span class=\"product\">"+$(this).attr('data-name')+"</span>\n" +
          "                <span style=\"float: right;margin-right: 0.1rem;\">"+discount+"折</span>\n" +
          "                <span class=\"zhe\"></span>\n" +
          "            </p>";
        $('.addzhekoudata').append(html);
      });
      $('.zhekou_mask').hide();//隐藏弹窗
      $('.zhekou').show();
    });
  });
  var mobileSelect4 = new MobileSelect({
    trigger: '#trigger4',
    title: '地区选择',
    wheels: [{data:[
        {
          id:'1',
          value:'1111',
          childs:[
            {id:'A1',value:'111'},
          ]
        }
      ]}],
    transitionEnd:function(indexArr, data){

    },
    callback:function(indexArr, data){
      $('#province').val(data[0].id);
      $('#city').val(data[1].id);
      $('#area').val(data[2].id);
    }
  });
  $.ajax({
    type: "post",
    url: "/api/ajax/area",
    dataType: "json",
    success: function(res){
      mobileSelect4.updateWheels(res.data);
    }
  });

  $('#sub').click(function(){
    if($('#name').val() == ""||$('#name').val() == null){
      layer.open({
        content: '代理商名称不能为空',
        skin: 'msg',
        time: 2 //2秒后自动关闭
      });
      return false;
    }
    if($('#province').val() == ""||$('#province').val() == null){
      layer.open({
        content: '请选择所在地区',
        skin: 'msg',
        time: 2 //2秒后自动关闭
      });
      return false;
    }
    if($('#address').val() == ""||$('#address').val() == null){
      layer.open({
        content: '请填写详细地址',
        skin: 'msg',
        time: 2 //2秒后自动关闭
      });
      return false;
    }
    if($('#contact').val() == ""||$('#contact').val() == null){
      layer.open({
        content: '请填写联系人',
        skin: 'msg',
        time: 2 //2秒后自动关闭
      });
      return false;
    }
    if(!(/^1[3456789]\d{9}$/.test($('#tel').val()))) {
      layer.open({
        content: '请输入正确的手机号码',
        skin: 'msg',
        time: 2 //2秒后自动关闭
      });
      return false;
    }
    if($('#agent_area').val() == ""||$('#agent_area').val() == null){
      layer.open({
        content: '请填写代理区域',
        skin: 'msg',
        time: 2 //2秒后自动关闭
      });
      return false;
    }
    if($('#dateSelectorOne').val() == ""||$('#dateSelectorOne').val() == null){
      layer.open({
        content: '请选择代理开始日期',
        skin: 'msg',
        time: 2 //2秒后自动关闭
      });
      return false;
    }
    if($('#dateSelectorTwo').val() == ""||$('#dateSelectorTwo').val() == null){
      layer.open({
        content: '请选择代理结束日期',
        skin: 'msg',
        time: 2 //2秒后自动关闭
      });
      return false;
    }
    if($('#yewuyuan').val() == ""||$('#yewuyuan').val() == null){
      layer.open({
        content: '请选择业务员',
        skin: 'msg',
        time: 2 //2秒后自动关闭
      });
      return false;
    }
    $('#form1').submit();
  });
</script>
<script>
  new Mdate("dateShowBtn", {
    //"dateShowBtn"为你点击触发Mdate的id，必填项
    acceptId: "dateSelectorOne",
    //此项为你要显示选择后的日期的input，不填写默认为上一行的"dateShowBtn"
    beginYear: "2019",
    //此项为Mdate的初始年份，不填写默认为2000
    beginMonth: "1",
    //此项为Mdate的初始月份，不填写默认为1
    beginDay: "1",
    //此项为Mdate的初始日期，不填写默认为1
    endYear: "2050",
    //此项为Mdate的结束年份，不填写默认为当年
    endMonth: "12",
    //此项为Mdate的结束月份，不填写默认为当月
    endDay: "31",
    //此项为Mdate的结束日期，不填写默认为当天
    format: "-"
    //此项为Mdate需要显示的格式，可填写"/"或"-"或".",不填写默认为年月日
  })
  new Mdate("dateStopBtn", {
    //"dateShowBtn"为你点击触发Mdate的id，必填项
    acceptId: "dateSelectorTwo",
    //此项为你要显示选择后的日期的input，不填写默认为上一行的"dateShowBtn"
    beginYear: "2019",
    //此项为Mdate的初始年份，不填写默认为2000
    beginMonth: "1",
    //此项为Mdate的初始月份，不填写默认为1
    beginDay: "1",
    //此项为Mdate的初始日期，不填写默认为1
    endYear: "2050",
    //此项为Mdate的结束年份，不填写默认为当年
    endMonth: "12",
    //此项为Mdate的结束月份，不填写默认为当月
    endDay: "31",
    //此项为Mdate的结束日期，不填写默认为当天
    format: "-"
    //此项为Mdate需要显示的格式，可填写"/"或"-"或".",不填写默认为年月日
  })
</script>

</html>
